var PATH_PREFIX ="";

function setPathPrefix(path){
	PATH_PREFIX =  path;
}

var serialNo = $("#serialNo").val();

$(function(){
	/*$("#table-mid").hide();
	$("#table-bot").hide();*/
	showTypeContent1('table-top');
});

$(function(){
	showPredictTime();
	makeData();
	queryClearStep();
});


var docGetTime = $("#docGetTime");
var startTime = $("#startTime");
var endTime = $("#endTime");
var changeTime = $("#changeTime");
var docExportTime = $("#docExportTime");

function showPredictTime(){
	var timestamp = new Date().getTime();
	timestamp = timestamp + 1.5 * 60 * 60 * 1000;
	var date  = new Date(timestamp);
	var hours = date.getHours();
	var minute = date.getMinutes();
	minute = minute < 10 ? "0" + minute : minute;
	var dateStr = /*hours*/"23" + ":" + "25";
	var predictTime = $("#predictTime");
	predictTime.html(dateStr);
}

function completeDocArchiveTable(obj,text){
	/*text = text.replace(" ","<br>");*/
	obj.html(text);
}


function completeDocReceiveTable(obj){
	if(obj != null && obj.length > 0){
		var textStr = "";
		for(var i = 0;i<obj.length;i++){
			textStr += "<tr>";
			textStr += 		"<td class='table-td-mid white-bg'>" + obj[i].clearstepDesc + "</td>";
			textStr += 		"<td class='table-td-mid white-bg'>" + obj[i].resultCode + "</td>";
			textStr += 		"<td class='table-td-mid white-bg'>" + obj[i].resultMsg + "</td>";
			textStr += 		"<td class='table-td-mid white-bg'>" + obj[i].createDate + "</td>";
			textStr += "</tr>";
		}
		var docReceive = $("#docReceiveTbody");
		docReceive.html(textStr);
		/*$("#table-mid").show();*/
	}
}
function completeDocExportTable(obj){
	if(obj != null && obj.length > 0){
		var textStr = "";
		for(var i = 0;i<obj.length;i++){
			textStr += "<tr>";
			textStr += 		"<td class='table-td-bot white-bg'>" + obj[i].clearstepDesc + "</td>";
			textStr += 		"<td class='table-td-bot white-bg'>" + obj[i].resultMsg + "</td>";
			textStr += 		"<td class='table-td-bot white-bg'>" + obj[i].createDate + "</td>";
			textStr += "</tr>";
		}
		var docExportTbody = $("#docExportTbody");
		docExportTbody.html(textStr);
		/*$("#table-bot").show();*/
	}
}


function queryClearStep(){
	$.ajax({
		async:true,
		url:PATH_PREFIX + 'queryClearStep.do',
		type:"post",
		dataType:'json',
		data:{
			serialNo : serialNo
		},
		success:function(data){
			
			if(!!data && !!data.groupList){
				var flag = true;
				if(data.groupList.length <= 0){
					$("ul[class*=steps] li:not(:first)").attr("class","clearStep");
				}else{
					$("ul[class*=steps] li:first").attr("class","clearStep active");
				}
				for(var i=0;i<data.groupList.length;i++){
					var vo =data.groupList[i];
					var className= "";
					switch (vo.clearStatus) {
					/*case "I":
						className = "load";
						break;
					case "F":
						className = "fail";
						break;
					case "S":
						className = "comp";
						break;	
					default:
						className = "load";
						break;*/
					case "I":
						className = "";
						break;
					case "F":
						className = "";
						break;
					case "S":
						className = "active";
						break;	
					default:
						className = "";
						break;
					}
					$("#"+vo.clearstepCode).attr("class","progress-icon " + className);
					$("#"+ "progressLine" + vo.clearstepCode).attr("class","progress-line " + className);
					if(vo.clearstepCode == '10005' && vo.clearStatus == 'S'){
						flag = false;
					}
				}
			}
			if(!!data && !!data.docArchiveList){
				completeDocReceiveTable(data.docArchiveList);
			}
			if(!!data && !!data.docExportList){
				completeDocExportTable(data.docExportList);
			}
			var clearVo = data.clearVo;
			if(!!data && !!clearVo){
				if(!!clearVo.docGetTime){
					completeDocArchiveTable(docGetTime,clearVo.docGetTime);
				}
				if(!!clearVo.clearStartTime){
					completeDocArchiveTable(startTime,clearVo.clearStartTime);
				}
				if(!!clearVo.clearEndTime){
					completeDocArchiveTable(endTime,clearVo.clearEndTime);
				}
				if(!!clearVo.docExportTime){
					completeDocArchiveTable(docExportTime,clearVo.docExportTime);
				}
				if(!!clearVo.changeDayTime){
					completeDocArchiveTable(changeTime,clearVo.changeDayTime);
				}
			}
			if($("#10001").attr("class").indexOf("active") > 0){
				$("#progress").css("width","20%");
			}
			if($("#10002").attr("class").indexOf("active") > 0){
				$("#progress").css("width","40%");
			}
			if($("#10003").attr("class").indexOf("active") > 0){
				$("#progress").css("width","60%");	
						}
			if($("#10004").attr("class").indexOf("active") > 0){
				$("#progress").css("width","80%");
			}
			if($("#10005").attr("class").indexOf("active") > 0){
				$("#progress").css("width","100%");
			}
			if(flag){
				setTimeout("queryClearStep()",1*1000);
			}
		}
	});		
}


function makeData(){
	$.ajax({
		async:true,
		url:PATH_PREFIX + 'makeData.do',
		type:"post",
		dataType:'json',
		data:{
			serialNo : serialNo
		},
		success:function(data){
		}
	});		
}


function showTypeContent1(id,tId){
	$(".typeContentClear").hide();
	$("#"+id).show();
};
